﻿using System;

using BEGDC.CC.BL.Workflow;
using BEGDC.CC.BL.Common;
using BEGDC.CC.BL.Common.Query;
using BEGDC.Utility.Castle;
using BEGDC.CC.Entity;

namespace BEGDC.CC.Web.UserControls
{
	/// <summary>
	/// Summary description for AccessControl.
	/// </summary>
	public class CVAccessControl: AccessControl
	{

		public override bool IsReadOnly
		{
			get
			{
				if( base.IsReadOnly )
				{
					return base.IsReadOnly;
				}
				else
				{
					if( this._currentStep == WorkTransition.CV_CATDIRECTORApprove || this._currentStep == WorkTransition.CV_PSOApprove
						|| this._currentStep == WorkTransition.CV_CODDirectorApprove || this._currentStep == WorkTransition.CV_CODVPApprove
						|| this._currentStep == WorkTransition.CV_Feedback )// || this._currentStep == WorkTransition.CV_Close)
					{
						return true;
					}
					else
						return false;
				}
			}
		}

		public override bool IsAttachmentReadOnly
		{
			get
			{
				if( this._currentStep == WorkTransition.CV_CATDIRECTORApprove || this._currentStep == WorkTransition.CV_PSOApprove
					|| this._currentStep == WorkTransition.CV_CODDirectorApprove || this._currentStep == WorkTransition.CV_CODVPApprove
					|| this._currentStep == WorkTransition.CV_Feedback )
				{
					return true;
				}
				else if(this._currentStep == WorkTransition.End && this._state!=SysDicItem.ProjectStatusFlag.Archive)
				{
					if(_state == SysDicItem.ProjectStatusFlag.Participation)
						return !this._isMgrOrStaff;
					else
						return true;
				}
				else
					return base.IsAttachmentReadOnly;
			}
		}

		public override bool IsButtonVisible(string name)
		{
			if(this.IsQuery)
			{
				switch(name)
				{
					case CVTransitionList.Copy:
						return this.ShowCopyButton();
						break;
					case CVTransitionList.Reply:
						return this.ShowReplyButton();
						break;
					case CVTransitionList.Save:
						return this.ShowSaveButton();
						break;
					default:
						return false;
				}
			}
			else
			{
				switch(name)
				{
					case CVTransitionList.Copy:
						return this.ShowCopyButton();
						break;
					case CVTransitionList.Reply:
						return this.ShowReplyButton();
						break;
					default:
					switch(this._currentStep)
					{
						case WorkTransition.Draft:
							if(name == CVTransitionList.Submit || name == CVTransitionList.Save)
								return true;
							else
								return false;
						case WorkTransition.CV_Apply:
							if(name == CVTransitionList.Submit || name == CVTransitionList.Save || name == CVTransitionList.Reply)
								return true;
							else
								return false;
						case WorkTransition.CV_ReApply:
							if(name == CVTransitionList.Submit || name == CVTransitionList.Save || name == CVTransitionList.Reply)
								return true;
							else
								return false;
						case WorkTransition.CV_Assignment:
							if(name == CVTransitionList.Assign || name == CVTransitionList.Reject || name == CVTransitionList.Save
								|| name == CVTransitionList.Check || name == CVTransitionList.Query || name == CVTransitionList.Reply)
								return true;
							else
								return false;
						case WorkTransition.CV_Check:
							if(name == CVTransitionList.Reject || name == CVTransitionList.Check || name == CVTransitionList.Query
								|| name == CVTransitionList.Save || name == CVTransitionList.Reply)
								return true;
							else
								return false;
						case WorkTransition.CV_CATDIRECTORApprove:
							if( name == CVTransitionList.Reject || name == CVTransitionList.Approve || name == CVTransitionList.Query
								|| name == CVTransitionList.Reply)
								return true;
							else
								return false;
						case WorkTransition.CV_PSOApprove:
							if( name == CVTransitionList.Reject || name == CVTransitionList.Approve || name == CVTransitionList.Query
								|| name == CVTransitionList.Reply)
								return true;
							else
								return false;
						case WorkTransition.CV_CODDirectorApprove:
							if( name == CVTransitionList.Reject || name == CVTransitionList.Approve || name == CVTransitionList.Query
								|| name == CVTransitionList.Reply)
								return true;
							else
								return false;
						case WorkTransition.CV_CODVPApprove:
							if( name == CVTransitionList.Reject || name == CVTransitionList.Approve || name == CVTransitionList.Query
								|| name == CVTransitionList.Reply)
								return true;
							else
								return false;
						case WorkTransition.CV_Feedback:
							if( name == CVTransitionList.Save || name == CVTransitionList.Submit //|| name == CVTransitionList.Query
								|| name == CVTransitionList.Reply)
								return true;
							else
								return false;
						case WorkTransition.CV_Close:
							if( name == CVTransitionList.Close)// || name == CVTransitionList.Query)
								return true;
							else
								return false;
					}
						return false;
						break;
				}
			}
		}
		
	}	
}
